{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [],
   "source": [
    "###################################\n",
    "## csv处理\n",
    "###################################\n",
    "import json\n",
    "import csv\n",
    "\n",
    "with open(\"rubin.json\", encoding=\"utf-8\") as f:\n",
    "    old = json.load(f)\n",
    "\n",
    "with open(\"rubin.csv\", encoding=\"utf-8\", mode=\"w\", newline=\"\")as f3:\n",
    "    csv_w = csv.writer(f3)\n",
    "    csv_w.writerow((\"id\",\"object_name\",\"object_type\", \"geography\", \"credit\",\"time_period\",\"dimensions\",\"medium\",\"previous_owner\",\"url\",\"cat2\",\"makers_job\",\"makers_name\",\"makers_born\",\"label\",\"img_url\",\"provenance\",\"bibliography\",\"cat1\",\"cat3\",\"library\"))\n",
    "\n",
    "for item in old:\n",
    "    d = {}\n",
    "    dd = old[item]\n",
    "    d[\"id\"] = None\n",
    "    d[\"object_name\"] = None\n",
    "    d[\"object_type\"] = None\n",
    "    d[\"geography\"] = None\n",
    "    d[\"credit\"] = None\n",
    "    d[\"time_period\"] = None\n",
    "    d[\"dimensions\"] = None\n",
    "    d[\"medium\"] = None\n",
    "    d[\"previous_owner\"] = None\n",
    "    d[\"url\"] = None\n",
    "    d[\"cat2\"] = None\n",
    "    d[\"makers_job\"] = None\n",
    "    d[\"makers_name\"] = None\n",
    "    d[\"makers_born\"] = None\n",
    "    d[\"label\"] = None\n",
    "    d[\"img_url\"] = None\n",
    "    d[\"provenance\"] = None\n",
    "    d[\"bibliography\"] = None\n",
    "    d[\"cat1\"] = None\n",
    "    d[\"cat3\"] = None\n",
    "    # ============================Rubin=========================\n",
    "    d[\"library\"] = \"Rubin Museum\"\n",
    "    d[\"id\"] = dd[\"Object number\"]\n",
    "    d[\"object_name\"] = dd[\"name\"]\n",
    "    try:\n",
    "        d[\"cat3\"] = dd[\"Classification(s)\"]\n",
    "    except:\n",
    "        pass\n",
    "    d[\"geography\"] = dd[\"Origin\"]\n",
    "    d[\"time_period\"] = dd[\"Date\"]\n",
    "    d[\"medium\"] = dd[\"Medium\"]\n",
    "    d[\"dimensions\"] = dd[\"Dimensions\"]\n",
    "    d[\"credit\"] = dd[\"Credit Line\"]\n",
    "    d[\"img_url\"] = \"muse33_\"+str(dd[\"id\"])\n",
    "    try:\n",
    "        d[\"label\"] = dd[\"Description\"]\n",
    "    except:\n",
    "        pass\n",
    "    # =======================David==========================\n",
    "    # d[\"library\"] = \"David Owsley Museum of Art\"\n",
    "    # img_url = str(dd[\"img_url\"][\"0\"]).replace(\"http://ballstate.dom5183.com:8080//Media/images/\", \"\").replace(\".jpg\",\"\")\n",
    "    # d[\"id\"] = img_url\n",
    "    # d[\"object_name\"] = dd[\"title\"]\n",
    "    # d[\"geography\"] = dd[\"mata\"][\"geography\"]\n",
    "    # d[\"credit\"] = dd[\"mata\"][\"credit\"]\n",
    "    # d[\"time_period\"] = dd[\"mata\"][\"time_period\"]\n",
    "    # d[\"dimensions\"] = dd[\"mata\"][\"dimensions\"]\n",
    "    # d[\"medium\"] = dd[\"mata\"][\"medium\"]\n",
    "    # d[\"img_url\"] = img_url\n",
    "    # d[\"cat3\"]  = dd[\"cat\"]\n",
    "    # ==========================Denver===============================\n",
    "    # d[\"library\"] = \"Denver Art Museum\"\n",
    "    # d[\"id\"] = str(dd[\"url\"]).replace(\"https://www.denverartmuseum.org/en/object/\", \"\")\n",
    "    # d[\"object_name\"] = dd[\"title\"]\n",
    "    # d[\"time_period\"] = dd[\"date\"]\n",
    "    # try:\n",
    "    #     d[\"cat3\"] = dd[\"keywords\"][0]\n",
    "    #     if len(dd[\"keywords\"])==3:\n",
    "    #         d[\"credit\"] = dd[\"keywords\"][1]\n",
    "    # except:\n",
    "    #     pass\n",
    "    # else:\n",
    "    #     d[\"medium\"] = dd[\"keywords\"][1]\n",
    "    #     d[\"credit\"] = dd[\"keywords\"][2]\n",
    "    # try:\n",
    "    #     d[\"geography\"] = dd[\"Country\"][0]\n",
    "    # except:\n",
    "    #     pass\n",
    "    # try:\n",
    "    #     d[\"dimensions\"] = dd[\"Dimensions\"][0]\n",
    "    # except:\n",
    "    #     pass\n",
    "    # try:\n",
    "    #     d[\"makers_name\"] = dd[\"Artist\"][0]\n",
    "    # except:\n",
    "    #     pass\n",
    "    # try:\n",
    "    #     d[\"makers_born\"] = dd[\"Artist\"][1]\n",
    "    # except:\n",
    "    #     pass\n",
    "    # try:\n",
    "    #     d[\"makers_job\"] = dd[\"Artist\"][2]\n",
    "    # except:\n",
    "    #     pass\n",
    "    # d[\"object_type\"] = dd[\"Collection\"][0]\n",
    "    # ps = dd[\"paragraph_2\"]\n",
    "    # try:\n",
    "    #     d[\"label\"] = ps[len(ps)-1]\n",
    "    # except:\n",
    "    #     pass\n",
    "    # d[\"img_url\"] = str(dd[\"img_url\"]).replace(\"https://s3.amazonaws.com/damcollections/\",\"\").replace(\"/2000/2000_thumb.jpg\", \"\")\n",
    "    # ================================Asia Society Museum===============\n",
    "    # d[\"id\"] = dd[\"id\"]\n",
    "    # d[\"library\"] = \"Asia Society Museum\"\n",
    "    # d[\"object_name\"] = dd[\"name\"]\n",
    "    # d[\"geography\"] = dd[\"location\"]\n",
    "    # try:\n",
    "    #     d[\"medium\"] = dd[\"material\"]\n",
    "    # except:\n",
    "    #     pass\n",
    "    # d[\"dimensions\"] = dd[\"size\"]\n",
    "    # d[\"credit\"] = dd[\"source\"]\n",
    "    # d[\"img_url\"] = \"muse31_\"+str(dd[\"id\"])\n",
    "    # try:\n",
    "    #     d[\"label\"] = dd[\"Introduction\"]\n",
    "    # except:\n",
    "    #     pass\n",
    "    strlist = []\n",
    "    for i in d:\n",
    "        if d[i]==None:\n",
    "            s = ''\n",
    "        else:\n",
    "            s = str(d[i])\n",
    "        strlist.append(s)\n",
    "    with open(\"rubin.csv\", encoding=\"utf-8\", mode=\"a\", newline=\"\")as f1:\n",
    "        csv_w = csv.writer(f1)\n",
    "        csv_w.writerow(strlist)\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import csv\n",
    "\n",
    "f1 = pd.read_csv(\"total_data2.csv\")\n",
    "f2 = pd.read_csv(\"muse.csv\")\n",
    "\n",
    "f = pd.concat([f1,f2])\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import csv\n",
    "\n",
    "f1 = pd.read_csv(\"rubin.csv\")\n",
    "f2 = pd.read_csv(\"denver.csv\")\n",
    "f3 = pd.read_csv(\"david.csv\")\n",
    "f4 = pd.read_csv(\"aisasociety.csv\")\n",
    "\n",
    "\n",
    "count = 13722\n",
    "\n",
    "\n",
    "id_list = []\n",
    "for row in f1.iterrows():\n",
    "    id_list.append(count)\n",
    "    count += 1\n",
    "f1['object_id'] = id_list\n",
    "f1.to_csv(\"muse1.csv\", index=False)\n",
    "\n",
    "\n",
    "# count"
   ]
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "7b4b4feff2f24a0f0a34464dbe537a36fda679851528fb8735cb41fa49dffb2d"
  },
  "kernelspec": {
   "display_name": "Python 3.8.3 ('base')",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
